package com.lotusfall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lotusfall.mapper.HouseResourcesMapper;
import com.lotusfall.pojo.HouseResource;
import com.lotusfall.service.HouseResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouseResourcesServiceImpl implements HouseResourcesService {
    @Autowired
    HouseResourcesMapper houseResourcesMapper;

    @Override
    public int saveHouseResources(HouseResource houseResource) {
        return this.houseResourcesMapper.saveHouseResources(houseResource);
    }

    @Override
    public PageInfo<HouseResource> queryHouseResourcesList(int page, int pageSize) {
        PageHelper.startPage(page,pageSize);
        List<HouseResource> houseResourceList = this.houseResourcesMapper.queryHouseResourcesList(page,pageSize);
        PageInfo<HouseResource> houseResourcePageInfo = new PageInfo<HouseResource>(houseResourceList);
        return houseResourcePageInfo;
    }

    @Override
    public HouseResource queryHouseResourcesById(Long id) {
       return this.houseResourcesMapper.queryHouseResourcesById(id);
    }

    @Override
    public boolean updateHouseResource(HouseResource houseResources) {
        if(this.houseResourcesMapper.updateHouseResource(houseResources) == 1)return true;
        return false;
    }

    // rentmethod
    @Override
    public PageInfo<HouseResource> queryHouseResourcesListByNum(Integer page, Integer pageSize, Integer type, Integer ori, Integer area, Integer rent) {
        PageHelper.startPage(page,pageSize);

        List<HouseResource> houseResourceList = this.houseResourcesMapper.queryHouseResourcesListByCondition(page,pageSize,type,ori,area,rent);
        PageInfo<HouseResource> houseResourcePageInfo = new PageInfo<HouseResource>(houseResourceList);
        return houseResourcePageInfo;
    }
}
